home *** CD-ROM | disk | FTP | other *** search
- Path: haystack.physio-control.com!usenet
- From: Brian Reese <breese@kahuna>
- Newsgroups: comp.lang.c
- Subject: Re: Converting Strings to Upper Case
- Date: Tue, 19 Mar 96 11:36:29 PDT
- Organization: Physio Control, Inc.
- Message-ID: <NEWTNews.827264485.11654.breese@PC_Breese.physio-control>
- References: <4ifra6$52i@scipio.cyberstore.ca> <4ih7l3$526@thrush.sover.net> <4ihl4m$4ca@castle.nando.net> <NEWTNews.827184423.14391.breese@PC_Breese.physio-control> <314eb83f.308884702@nntp.ix.netcom.com>
- NNTP-Posting-Host: pc_breese.physio-control.com
- Mime-Version: 1.0
- Content-Type: TEXT/PLAIN; charset=US-ASCII
- X-Newsreader: NEWTNews & Chameleon -- TCP/IP for MS Windows from NetManage
-
-
- In article <314eb83f.308884702@nntp.ix.netcom.com>, <miker3@ix.netcom.com>
- writes:
- > Brian Reese <breese@kahuna> wrote:
- > > Here's my offering:
- > >
- > > #include <stdio.h> /* for printf() */
- > > #include <ctype.h> /* for toupper() */
- > >
- > > char * strtoupper( char * ); /* converts string to upper case */
- > >
- > > int main( void )
- > > {
- > > char * test = "my test string";
- > >
- > > printf( "%s\n", test );
- > > printf( "%s\n", strtoupper( test ) );
- > >
- > > return 0;
- > > }
- > >
- > > char * strtoupper( char * ptr ) /* converts string to upper case */
- > > {
- > > char * save_ptr = ptr; /* save pointer for return */
- > >
- > > while ( *ptr = toupper( *ptr++ ) )
- > > ;
- > > return save_ptr;
- > > }
- >
- > Not a very good offering. There are two obvious problems in your
- > example.
- >
- > First, the identifier strtoupper with external linkage is reserved.
- > Defining your own function with external linkage with this name
- > results in undefined behavior.
- >
- > Second, the expression
- >
- > *ptr = toupper( *ptr++ )
- >
- > modifies ptr and also acesses its value other than to determine the
- > new value without an intervening sequence point. This too results in
- > undefined behavior.
- >
- > Michael M Rubenstein
-
- Well, Michael, thanks for the corrections. I did compile and run the
- above code before posting it, and it worked, but as you said, the
- behavior is undefined. I got lucky (if you care to call that lucky).
-
- Brian
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-